package com.itheima.app.controller.omsController;

import com.itheima.app.manager.omsManager.OmsOrderReturnApplyManager;
import com.itheima.commons.R;
import com.itheima.domain.db.oms.OmsOrderReturnApply;
import com.itheima.dto.OmsOrderReturnApplyDto;
import com.itheima.vo.OmsReturnApplyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 退货申请
 *
 * @author DogeGuo
 */
@CrossOrigin    //跨域
@RestController
public class OmsOrderReturnApplyController {
    @Autowired
    OmsOrderReturnApplyManager omsOrderReturnApplyManager;

    /**
     * 分页查询退货申请
     *
     * @return
     */
    @GetMapping("/returnApply/list")
    public R pageReturnWithParams(OmsOrderReturnApplyDto dto,
                                  @RequestParam(value = "pageNum", defaultValue = "1", required = false) Integer pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "10", required = false) Integer pageSize) {

        return omsOrderReturnApplyManager.pageReturnWithParams(dto, pageNum, pageSize);
    }

    /**
     * 获取退货申请详情
     *
     * @param id
     * @return
     */
    @GetMapping("/returnApply/{id}")
    public R getInfoById(@PathVariable Integer id) {
        OmsReturnApplyVo vo = omsOrderReturnApplyManager.getInfoById(id);
        return R.ok(vo);
    }

    /**
     * 修改退货申请状态
     *
     * @param id
     * @param omsOrderReturnApply
     * @return
     */
    @PostMapping("/returnApply/update/status/{id}")
    public R updateStatusById(@PathVariable Integer id, @RequestBody OmsOrderReturnApply omsOrderReturnApply) {
        omsOrderReturnApplyManager.updateStatusById(id, omsOrderReturnApply);
        return R.ok(null);
    }

    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/returnApply/delete")
    public R deleteByIds(Integer[] ids) {
        omsOrderReturnApplyManager.deleteByIds(ids);
        return R.ok(null);
    }
}
